<?php

class FormUserRecovery extends CFormModel
{
	public $email;
	public $id;
	
	public function rules()
	{
		return array(
			array('email', 'required'),
			array('email', 'email'),
			array('email', 'validateExistance'),
		);
	}
	
	public function attributeLabels()
	{
		return array(
			'email' => UserModule::t('E-mail'),
		);
	}
	
	public function validateExistance($attribute, $params)
	{
		if(!$this->hasErrors())
		{
			$model = User::model()->notsafe()->findByAttributes(array('email' => $this->email));
			
			if($model)
			{
				$this->id = $model->id;
			}
			
			// We will not report errors if the email is not found, because this would enable spoofing
		}
	}
	
}